package org.excample.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.excample.entity.PageBean;
import org.excample.entity.Quality;
import org.excample.entity.User;
import org.excample.mapper.QualityMapper;
import org.excample.service.QualityService;
import org.excample.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class QualityServiceImpl implements QualityService {
    @Autowired
    private QualityMapper qualityMapper;

    @Override
    public void insertQuality(Quality quality) {
//        Map<String,Object> map = ThreadLocalUtil.get();
//        Integer id = (Integer) map.get("id");
//        quality.setId(id);
       qualityMapper.insertQuality(quality);
    }


    @Override
    public PageBean<Quality> select(Integer pageNum, Integer pageSize) {
        PageBean<Quality> pb = new PageBean<>();
        // 初始化分页参数
        PageHelper.startPage(pageNum, pageSize);
        List<Quality> qualityList = qualityMapper.select();
        Page<Quality> page = (Page<Quality>) qualityList;
        pb.setTotal(page.getTotal());
        pb.setItem(page.getResult());
        return pb;
    }

    @Override
    public User findName(String name) {
        return null;
    }


}
